﻿@page "/issues/mainplan/{MainPlanId}"
@inject IMainPlanService MainPlanService
@inject IIssueService IssueService
<PageTitle>主计划异常列表</PageTitle>
<div class="row position-relative">
    <div class="col">
        <h5>
            <CompMainPlanStatus Status="@_mainPlanDto.Status"></CompMainPlanStatus>
            <span> @_mainPlanDto.Number @_mainPlanDto.Name</span>
        </h5>
    </div>
    <CompAddButton Roles="" Url="@($"issue/add/{MainPlanId}")" />
</div>
@if (_mainPlanDto.Id != null)
{
    @foreach (var issue in _issueDtos)
    {
        <IssueRow IssueDto="issue" />
    }
}

@code {
    [Parameter]
    public string MainPlanId { get; set; }
    private MainPlanDto _mainPlanDto = new();
    private List<IssueDto> _issueDtos = new();

    protected override async Task OnParametersSetAsync()
    {
        var mResult = await MainPlanService.GetFirstOrDefaultAsync(Guid.Parse(MainPlanId));
        if (mResult.Status) _mainPlanDto = mResult.Result;

        _issueDtos.Clear(); 
        _issueDtos.AddRange(await IssueService.GetAllByMainPlanIdAsync(_mainPlanDto.Id.Value));
    }
}
